Skip to content

feat(data-classes): support for code pipeline job event #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 17, 2021

Conversation

michaelbrewer
Copy link
Contributor

@michaelbrewer michaelbrewer commented May 4, 2021

Issue #, if available:

https://github.com/awslabs/aws-lambda-powertools-python/issues/414

Description of changes:

Add support for CodePipeline Job event data class

Code example based on the docs:

from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.data_classes import CodePipelineJobEvent
logger = Logger()
def lambda_handler(event, context):
    """The Lambda function handler
    If a continuing job then checks the CloudFormation stack status
    and updates the job accordingly.
    If a new job then kick of an update or creation of the target
    CloudFormation stack.
    """
    event: CodePipelineJobEvent = CodePipelineJobEvent(event)
    # Extract the Job ID
    job_id = event.get_id
    # Extract the params
    params: dict = event.decoded_user_parameters
    stack = params["stack"]
    artifact_name = params["artifact"]
    template_file = params["file"]
    try:
        if event.data.continuation_token:
            # If we're continuing then the create/update has already been triggered
            # we just need to check if it has finished.
            check_stack_update_status(job_id, stack)
        else:
            # down from S3 using the credentials
            template = event.get_artifact(artifact_name, template_file)
            # Kick off a stack update or create
            start_update_or_create(job_id, stack, template)
    except Exception as e:
        # If any other exceptions which we didn't expect are raised
        # then fail the job and log the exception message.
        logger.exception("Function failed due to exception.")
        put_job_failure(job_id, "Function exception: " + str(e))
    logger.debug("Function complete.")
    return "Complete."

Checklist

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter
Copy link

codecov-commenter commented May 4, 2021

Codecov Report

Merging #416 (93f92a7) into develop (93fad02) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           develop     #416    +/-   ##
=========================================
  Coverage    99.89%   99.90%            
=========================================
  Files          101      102     +1     
  Lines         3996     4117   +121     
  Branches       199      204     +5     
=========================================
+ Hits          3992     4113   +121     
  Misses           1        1            
  Partials         3        3            
Impacted Files Coverage Δ
...mbda_powertools/utilities/data_classes/__init__.py 100.00% <100.00%> (ø)
.../utilities/data_classes/code_pipeline_job_event.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93fad02...93f92a7. Read the comment docs.

@heitorlessa heitorlessa added feature New feature or functionality area/utilities labels May 5, 2021
@heitorlessa
Copy link
Contributor

Lemme know when it's ready. I think you mentioned about adding an UTF decode before finalizing the implementation

@michaelbrewer
Copy link
Contributor Author

@heitorlessa i added some docs for this. So i think it is ready :)

@michaelbrewer
Copy link
Contributor Author

@jplock if you want to have a look too

@michaelbrewer
Copy link
Contributor Author

@heitorlessa anything missing here?

@heitorlessa
Copy link
Contributor

heitorlessa commented May 13, 2021 via email

@heitorlessa heitorlessa added this to the 1.16.0 milestone May 17, 2021
Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for working on this!

Note to self - Find a better name for this utility in 2.0, something like event source

@heitorlessa heitorlessa merged commit 22754d3 into aws-powertools:develop May 17, 2021
@michaelbrewer michaelbrewer deleted the feat-code-pipeline-event branch May 17, 2021 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants